const app = getApp()

Page({
  data: {
    dataList:[{
      date: "2023-11-9",
      time: "14:32:32",
      kilo: "2.12",
      hour: "0",
      min: "1",
      sec: "23"
    },
    {
      date: "2023-11-19",
      time: "14:32:32",
      kilo: "2.12",
      hour: "0",
      min: "1",
      sec: "23"
    }
  ],
    userID: '',
    userName: ''
  },
  getPageList(){
    wx.showLoading({
      title: '加载中',
    })
    let db = wx.cloud.database()
    let userCollection = db.collection('run')
    userCollection.where({
      id: this.data.userID
    }).get().then(res =>{
      console.log("数据查询成功", res)
      console.log("第一个数据", res.data[0])
      
      // var tempList = []
      // res.data.forEach((elem) => tempList.push({date: elem.date, time: elem.when, kilo: elem.kilometer, hour: elem.hour, min: elem.min, sec: elem.sec}))

      //  this.setData({
      //    dataList: tempList
      //  })
      console.log("dataList", this.data.dataList)
      console.log("第二个数据", res.data[1])
      wx.showToast({
        title: '加载完成',
      })
    })
  },
  onShow(){
    this.setData({
      userID: app.globalData.userID,
      userName: app.globalData.nickname,
    })
    console.log("用户ID", this.data.userID)
    console.log("用户名称", this.data.userName)
    this.getPageList()

  }
  
})
